<?php
namespace Home\Controller;
use Home\Controller\IndexController;

class RunController extends IndexController {

    //暂缓流失方法
    public function add() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);

        $id = I('get.id');
        if (IS_POST) {
            $model = D('Home/Run');
            if ($model->validate($model->_step)->create(I('post.'), 4)) {
                //追加暂缓措施
                $data['id']=I('post.id');
                $data['status']='暂缓流失';
                $_step=$model->field('step')->find($data['id']);
                $data['step']=$_step['step'].'<br/>'.I('post.step');
                $model->data($data)->save();
                $this->success('操作成功！', U('lst', array('p' => $p)));
                exit;
            }
            $this->error($model->getError());
        }
        $model = M('Run');
        $data = $model->find($id);
        // var_dump($data);
        $this->assign('data', $data);

        $this->display();
    }

    //确认流失方法
    public function edit() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);

        $id = I('get.id');
        if (IS_POST) {
            $model = D('Home/Run');
            if ($model->validate($model->_why_run)->create(I('post.'), 5)) {
                 if($model->save() !== FALSE) {
                    $this->success('操作成功！', U('lst', array('p' => $p)));
                    exit;
                }
            }
            $this->error($model->getError());
        }
        $model = M('Run');
        $data = $model->find($id);
        $this->assign('data', $data);

        $this->display();
    }

    public function delete() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);

        $model = D('Home/Run');
        if ($model->delete(I('get.id', 0)) !== FALSE) {
            $this->success('删除成功！', U('lst', array('p' => I('get.p', 1))));
            exit;
        } else {
            $this->error($model->getError());
        }
    }

    public function lst() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);

        $model = D('Home/Run');
        $data = $model->search();
        $this->assign(array(
            'data' => $data['data'],
            'page' => $data['page'],
        ));
        //var_dump($data['data']);

        $this->display();
    }

}
